<?php namespace App\Http\Controllers\user\api;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;
use Input;
use App\Models\News;


class NewsController extends Controller {

	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */
	public function index()
	{
		//
	}

	public function getNews()
	{
		$current = (int)Input::get('current',0);
		$rowCount = (int)Input::get('rowCount',10);
		$type = (int)Input::get('type',0);
		$hot = Input::get('hot',null);
		if($hot){
			$data = News::where('is_recommanded', 1);
			$count = $data->count();
			$news = $data->orderBy("news_rank", 'DESC')->skip($current)->take($rowCount)->get();
		}else{
			$data = News::where('type',$type);
			$count = $data->count();
			$news = $data->skip($current)->take($rowCount)->get();
		}
		$arr = array(
			'current'	=> $current,
			'rowCount'	=> $rowCount,
			'total'		=> $count,
			'data'		=> $news
			);
		return $this->json($arr);
	}

	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function create()
	{
		//
	}

	/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
	public function store()
	{
		//
	}

	/**
	 * Display the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		//
	}

	/**
	 * Show the form for editing the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		//
	}

	/**
	 * Update the specified resource in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		//
	}

	/**
	 * Remove the specified resource from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		//
	}

}
